package com.qiwx.pigeon.adapter.home;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.qiwx.pigeon.R;
import com.qiwx.pigeon.data.CageStatusConfig;
import com.qiwx.pigeon.data.db.CageRepairModel;
import com.qiwx.pigeon.data.vo.CageRemindBean;
import com.qiwx.pigeon.data.vo.CageRepairBean;

import java.util.List;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-06 11:26
 * 鸽笼维修 Adapter
 **/
public class CageRepairAdapter extends BaseQuickAdapter<CageRepairBean, BaseViewHolder> {

    ICageInterface iCageInterface;

    public CageRepairAdapter(int layoutResId, List<CageRepairBean> data) {
        super(layoutResId, data);
    }

    public void setIPigeonPairInterface(ICageInterface iCageInterface) {
        this.iCageInterface = iCageInterface;
    }

    @Override
    protected void convert(BaseViewHolder holder, CageRepairBean bean) {
        holder.setText(R.id.txt_c_number, bean.getC_number() + "");
        holder.setText(R.id.txt_status, getRePairContent(bean));
        holder.getView(R.id.btn_kl).setVisibility(View.GONE);
        holder.setText(R.id.btn_opreate, "操作");

        holder.findView(R.id.btn_opreate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iCageInterface != null) {
                    iCageInterface.onSelectId(holder.getAdapterPosition(), bean.getC_id(),0);
                }

            }
        });

    }

    private String getRePairContent(CageRepairBean model) {
        StringBuffer sb = new StringBuffer();
        if (model.getIs_cage_repair()==1) {
            sb.append("窝笼");
            sb.append(" ,");
        }
        if (model.getIs_wather_cup()==1) {
            sb.append(" 水杯");
            sb.append(" ,");
        }
        if (model.getIs_need_hwb()==1) {
            sb.append(" 缺窝布");
            sb.append(" ,");
        }
        if (model.getIs_fasten()==1) {
            sb.append(" 笼片加固");
            sb.append(" ,");
        }
        if (sb.length() <= 0) {
            return "暂无";
        } else {
            String content = sb.toString();
            if (content.lastIndexOf(",") > 0)
                content = content.substring(0, content.length() - 1);
            return content;
        }
    }
}
